import pandas as pd
from pymongo import MongoClient
import os

try:
    # 提供用户名和密码进行连接
    username = "root"
    password = "123456"
    connection_string = f'mongodb://{username}:{password}@192.168.101.11:27017/'
    client = MongoClient(connection_string)

    # 选择数据库
    db = client['imooc-manager']
    # 选择集合
    collection = db['rbs']

    # 读取集合中的数据
    cursor = collection.find()
    data = list(cursor)
    if data:
        df = pd.DataFrame(data)
        print("读取到的数据：")
        print(df)
    else:
        print("集合中没有数据。")

    # 删除集合
    collection.drop()
    print("集合已成功删除。")

    # 关闭 MongoDB 连接
    client.close()

except Exception as e:
    print(f"发生未知错误: {e}")